{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "improved-liabilities",
   "metadata": {},
   "source": [
    "# QComponent - Interdigitated transmon qubit"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "looking-velvet",
   "metadata": {},
   "source": [
    "This demo notebook goes over how to use the interdigitated transmon component, similar to those describedin Gambetta et. al., IEEE Trans. on Superconductivity Vol. 27, No. 1 (2007). \n",
    "\n",
    "#### Preparation\n",
    "First, let's import the key libraries for qiskit metal: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "attached-report",
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit_metal as metal\n",
    "from qiskit_metal import designs, draw\n",
    "from qiskit_metal import MetalGUI, Dict #, open_docs"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8d66ee5",
   "metadata": {},
   "source": [
    "(temporary patch) the creation of the cpw geomeptries from the interdigitated transmon pins, appear to cause a short-edge error rooted into the precision of the point alignment. For the timebeing you can run the following cell to suppress said violation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e9116de",
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit_metal.toolbox_metal.math_and_overrides as mov\n",
    "mov.DECIMAL_PRECISION=7"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "continuing-tourism",
   "metadata": {},
   "source": [
    "#### Create the design\n",
    "Next, let's fire up the GUI: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "crazy-possibility",
   "metadata": {},
   "outputs": [],
   "source": [
    "design = designs.DesignPlanar()\n",
    "gui = MetalGUI(design)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "executed-childhood",
   "metadata": {},
   "source": [
    "The name of the component located in the qlibrary is \"Transmon_Interdigitated\" and we can take a look at the various input options:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "animal-speech",
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.Transmon_Interdigitated import TransmonInterdigitated\n",
    "TransmonInterdigitated.get_template_options(design)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "descending-municipality",
   "metadata": {},
   "source": [
    "Now let's create three transmons, each centered at a specific (x,y) coordinate: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "composed-parallel",
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.Transmon_Interdigitated import TransmonInterdigitated\n",
    "design.overwrite_enabled = True\n",
    "q1 = TransmonInterdigitated(design, 'qubit1', options=dict(pos_x='-2.0mm',orientation='-90'))\n",
    "q2 = TransmonInterdigitated(design, 'qubit2', options=dict(pos_x='2.0mm', orientation='90'))\n",
    "q3 = TransmonInterdigitated(design, 'qubit3', options=dict(pos_y='3.0mm', orientation='180'))\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "meaning-incident",
   "metadata": {},
   "source": [
    "To check that the qpin connections are functioning correctly, we'll connect these transmons with CPWs. Let's first connect qpin2 of \"qubit1\" to qpin3 of \"qubit3\". We can do this using the RouteMeander functionality. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "instant-courage",
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.tlines.meandered import RouteMeander"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "comparable-darkness",
   "metadata": {},
   "outputs": [],
   "source": [
    "ops=dict(fillet='90um')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "sudden-joint",
   "metadata": {},
   "outputs": [],
   "source": [
    "options = Dict(\n",
    "    total_length= '5mm',\n",
    "    pin_inputs=Dict(\n",
    "        start_pin=Dict(\n",
    "            component= 'qubit1',\n",
    "            pin= 'bus1'),\n",
    "        end_pin=Dict(\n",
    "            component= 'qubit3',\n",
    "            pin= 'bus2')),\n",
    "    lead=Dict(\n",
    "        start_straight='0.5mm',\n",
    "        end_straight='0.0mm'),\n",
    "    meander=Dict(\n",
    "       asymmetry='0mm'),\n",
    "    **ops\n",
    ")\n",
    "\n",
    "# Below I am creating a CPW without assigning its name.\n",
    "#  Therefore running this cell twice will create two CPW's instead of overwriting the previous one\n",
    "#  To prevent that we add the cpw.delete() statement.\n",
    "#  The try-except wrapping is needed to suppress errors during the first run of this cell\n",
    "try:\n",
    "    cpw.delete()\n",
    "except NameError: pass\n",
    "\n",
    "cpw1 = RouteMeander(design, options=options)\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "organized-metadata",
   "metadata": {},
   "source": [
    "Now let's connect qubit 2 to qubit 3:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "unknown-affiliate",
   "metadata": {},
   "outputs": [],
   "source": [
    "options = Dict(\n",
    "    total_length= '5mm',\n",
    "    pin_inputs=Dict(\n",
    "        start_pin=Dict(\n",
    "            component= 'qubit2',\n",
    "            pin= 'bus2'),\n",
    "        end_pin=Dict(\n",
    "            component= 'qubit3',\n",
    "            pin= 'bus1')),\n",
    "    lead=Dict(\n",
    "        start_straight='0.5mm',\n",
    "        end_straight='0.0mm'),\n",
    "    meander=Dict(\n",
    "       asymmetry='0mm'),\n",
    "    **ops\n",
    ")\n",
    "\n",
    "#try:\n",
    "#    cpw.delete()\n",
    "#except NameError: pass\n",
    "\n",
    "cpw2 = RouteMeander(design, options=options)\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "future-cleveland",
   "metadata": {},
   "source": [
    "And finally, let's connect pin3 of qubit1 to pin2 of qubit 2: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "downtown-burton",
   "metadata": {},
   "outputs": [],
   "source": [
    "options = Dict(\n",
    "    total_length= '8mm',\n",
    "    pin_inputs=Dict(\n",
    "        start_pin=Dict(\n",
    "            component= 'qubit1',\n",
    "            pin= 'bus2'),\n",
    "        end_pin=Dict(\n",
    "            component= 'qubit2',\n",
    "            pin= 'bus1')),\n",
    "    lead=Dict(\n",
    "        start_straight='0.5mm',\n",
    "        end_straight='0.5mm'),\n",
    "    meander=Dict(\n",
    "       asymmetry='0mm'),\n",
    "    **ops\n",
    ")\n",
    "\n",
    "#try:\n",
    "#    cpw.delete()\n",
    "#except NameError: pass\n",
    "\n",
    "cpw2 = RouteMeander(design, options=options)\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25bd25c7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
